﻿using System.Diagnostics;
using LFSRecord2.Model.Undo;

namespace LFSRecord2.Model.UserActions
{
    public class UserActionDeleteAudioRegion : UserActionBase
    {
        // Action description, so we can replay this action (and reverse it)
        public int LayerIndex { get; set; }

        public AudioRegionData RegionData { get; set; }

        public UserActionDeleteAudioRegion()
        {
            Action = UserActionTypes.DeleteAudioRegion;
        }

        public override void DoUndo()
        {
            Debug.WriteLine("Undoing a DeleteAudioRegion action");
            LfsRecordController.project.DeselectAll();
            LfsRecordController.project.AudioLayers[LayerIndex].ReinstateAudioRegion(RegionData);
        }

        public override void DoRedo()
        {
            Debug.WriteLine("Redoing a DeleteAudioRegion action");
            for (int a = 0; a < LfsRecordController.project.AudioLayers[LayerIndex].AudioRegions.Count; a++)
            {
                if (LfsRecordController.project.AudioLayers[LayerIndex].AudioRegions[a].RegionIndex == RegionData.RegionIndex)
                {
                    LfsRecordController.project.AudioLayers[LayerIndex].AudioRegions[a].Dispose();
                    LfsRecordController.project.AudioLayers[LayerIndex].AudioRegions.RemoveAt(a);
                    break;
                }
            }
        }
    }
}
